package com.example.user.service.application.service;

import com.example.user.service.application.command.CreateUserCommand;
import com.example.user.service.application.port.in.CreateUserUseCase;
import com.example.user.service.domain.User;
import com.example.user.service.domain.port.CreateUserPort;
import com.example.user.service.domain.valueobject.*;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CreateUserService implements CreateUserUseCase {
    @Resource
    private CreateUserPort createUserPort;
    @Override
    public User createUser(CreateUserCommand createUserCommand) {
        //command -> domain
        User user=new User(
                new UserName(createUserCommand.name()),
                new UserAge(createUserCommand.age()),
                new Email(createUserCommand.email()),
//                new Password( createUserCommand.password())
                Password.fromRaw(createUserCommand.password()),
                new IsSuper(createUserCommand.isSuper())
        );
        log.info("user:{}",user);
        return createUserPort.createUser(user);
    }
}
